<?php
class form
{
//自动输出
static $autoshow=true;
//非自动输出时的缓存
static $html=null;
//多输入框控件设置数组
static $someinput_set=array(
'mei'=>100,
'new'=>5,
'add'=>1,
'isuc'=>true,
'issymbian'=>true,
'istextarea'=>true,
);
static function html_valuestr($name,$value,$selected=null){
 $html=null;
 foreach($name as $i=>$n)
 {
if($selected===null or $selected[$i])
 $html.=' '.$n.'="'.htmlspecialchars($value[$i],ENT_COMPAT,'utf-8').'"';
 }
return $html;
}
static function someinput_set($set)
{
 if(!is_array($set))
  return false;
 if($set['mei']<1)
  $set['mei']=100;
 if($set['new']<1)
  $set['new']=5;
 if($set['add']<0)
  $set['add']=0;
 elseif($set['add']===null)
  $set['add']=1;
 self::$someinput_set=$set+self::$someinput_set;
}
static function someinput_put($name,$value,$size=null,$other=null)
{
$value=str_replace(array("\r\n","\r"),"\n",$value);
$set=self::$someinput_set;
if(strlen($set['plugreplace'])>0) $value=str_replace('+',$set['plugreplace'],$value);
$len=iconv_strlen($value,'utf-8');
$page=ceil($len/$set['mei'])+$set['add'];
if($page<$set['new'])
 $page=$set['new'];
if($set['istextarea'])
{
$html1="<textarea name=\"{$name}[]\"";
if(is_array($size))
 {
  $html1.=self::html_valuestr(array('rows','cols'),$size,$size);
 }
elseif($size)
 $html1.=" rows=\"{$size}\"";
$html1.=">";
$html2='</textarea><br/>';
}
else
{
$html1="<input name=\"{$name}[]\"";
if(is_array($size))
 $size=$size[0];
if($size) $html1.=" size=\"{$size}\"";
$html1.=' value="';
$html2='"/><br/>';
}
$html=null;
for($i=0;$i<$page;$i++)
{
$off=$set['mei']*$i;
$text=str_replace(array("\xC2\xA0",' ',"\n"),array('&nbsp;','&nbsp;',"&#13;&#10;"),htmlspecialchars(iconv_substr($value,$off,$set['mei'],'utf-8'),ENT_COMPAT,'utf-8'));
if($set['isuc'] && $text!=='')
 $text="\x03".$text."\x03";
  $html.=$html1.$text.$html2;
 }
if(self::$autoshow)
 echo $html;
else
 self::$html.=$html;
}
static function someinput_get($name,$post=null)
{
if($post===null) $post=$_POST;
$set=self::$someinput_set;
$value=null;
if($set['isuc'])
{
$post=$post[$name];
foreach($post as $text)
 {
if(substr($text,0,1)=="\x03")
 $text=substr($text,1);
if(substr($text,-1,1)=="\x03")
 $text=substr($text,0,strlen($text)-1);
$value.=$text;
 }
}
else
 {ksort($post[$name]);
$value=implode(null,$post[$name]);}
if($set['issymbian'])
 $value=str_replace(array(chr(12),"\xC2\xA0"),array("\n",' '),$value);
if(strlen($set['plugreplace'])>0) $value=str_replace($set['plugreplace'],'+',$value);
return $value;
}
/*CLASS END*/
}
?>